/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) 
{
    struct ListNode *a = headA, *b = headB;
    int la,lb,al;
    la=lb=al=0;
    while(a->next!=NULL)
    {
        a = a->next;
        ++la;
    }
       while(b->next!=NULL)
    {
        b = b->next;
        ++lb;
    }
    if(a!=b)
    {
        return NULL;

    }
    al = abs(la-lb);
    if (la >= lb ) a=headA,b=headB ;
    else a=headB,b=headA;
    while(al--)
    {
        a=a->next;
    }
    while(a!=b)
    {
        a=a->next;
        b=b->next;
    }
    return a;
}